package com.jiyun.controller;

import com.alibaba.nacos.common.utils.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jiyun.pojo.Coupon;
import com.jiyun.pojo.JsonRes;
import com.jiyun.service.CouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author: 刘清芳
 * @description:
 * @date: 2024/1/2 16:52
 */
@RestController
@RequestMapping("coupon")
public class CouponController {
    @Autowired
    CouponService couponService;

    @PostMapping("/findAllCoupon")
    public Page<Coupon> findAllCoupon(@RequestBody Coupon coupon, @RequestParam Integer pageNum, @RequestParam Integer pageSize) {

// 调用couponService的page方法，根据分页对象和封装好的查询条件进行查询，并返回结果
//        return couponService.page(couponPage, wrapper);
        return couponService.findAllCoupon(coupon, pageNum,pageSize);
    }

    //    添加修改
    @PostMapping("/add")
    public void add(@RequestBody Coupon coupon) {
        coupon.setRemoval(1);
        couponService.saveOrUpdate(coupon);
    }

    //    逻辑删除
    @PostMapping("/deleteById")
    public JsonRes deleteById(Integer id) {
        return couponService.deleteById(id);
    }

}
